package com.feilx.changgou.pay.controller;

import com.changgou.utils.Result;
import com.changgou.utils.StatusCode;
import com.feilx.changgou.pay.service.WeixinPayService;
import com.github.wxpay.sdk.WXPayUtil;
import org.apache.http.HttpRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.io.ByteArrayOutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@RestController
@RequestMapping(value = "/weixin/pay")
public class WeiXinPayController {

    @Autowired
    private WeixinPayService weixinPayService;
    /**
     * 创建支付二维码
     *
     */

   /**
   *@Description  创建二维码 配合前端 Qrcode.js完成前端二维码创建
   */
   @RequestMapping(value = "/create/native")
   public Result createNative(@RequestParam Map<String,String> paramsMap){
       Map map = weixinPayService.createNative(paramsMap);
       return new Result(true, StatusCode.OK,"创建二维码成功",map);
   }

   // 查询支付状态
    @GetMapping("/status/query")
    public  Result queryStatus(String outtradeno){
        Map map = weixinPayService.queryWeixinPayStatus(outtradeno);
        return new Result(true, StatusCode.OK,"查询支付状态成功",map);
    }

    // 微信支付结果通知回调方法
    @RequestMapping("/notify/url")
    public String notifyurl(HttpServletRequest request){
      return weixinPayService.notifyUrl(request);
    }

}
